package com.project.class8_18;

import com.lovo.netCRM.component.LovoImageLabel;

import javax.swing.*;

public class MyJFrame extends JFrame implements Runnable{
    private LovoImageLabel imgLabel= new LovoImageLabel(50,50,200,200,
            this,"img/5.jpg");

    public MyJFrame(){
        this.setLayout(null);

        this.setSize(800,600);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);

        //启动线程
        new Thread(this).start();
    }

    public static void main(String[] args) {
        new MyJFrame();
    }

    private int speed = 5;
    @Override
    public void run() {
        while(true){
            int x = imgLabel.getX();
            int y = imgLabel.getY();
            if(x > 600 || x < 0){
                speed *= -1;
            }

            imgLabel.setLocation(x + speed,y);


            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
